/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package blms.domain;

import java.io.Serializable;
import java.util.Set;

/**
 * An {@link Expression} object represents a arithmetic expression with
 * variables that may use 4 arithmetic operators with the usual precedence and
 * associativity as well as parentheses.
 * 
 * @see Context
 * @see LeagueContext
 * @see MapContextAdapter
 * 
 * @author João Arthur
 * @author Jonhnny Weslley
 * @author Thiago Emmanuel
 * @version 1.00, 25/04/2008
 * @since 1.0
 */
public interface Expression extends Serializable {

	/**
	 * Evaluates the {@link Expression} value using the variables from the
	 * {@link Context}
	 * 
	 * @param context
	 *            the {@link Context}
	 * @return the expression value
	 * @throws ArithmeticException
	 *             if an exceptional arithmetic condition has occurred.
	 */
	int evaluate(Context context);

	/** A {@link Context} maps a variable name to Integer object holding value */
	interface Context {

		/**
		 * Returns the value to which the specified variable name is associated
		 * 
		 * @param name
		 *            the variable name whose associated value is to be returned
		 */
		int getVariable(String name);

		/**
		 * Returns a {@link Set} of the variable names contained in this
		 * context.
		 */
		Set<String> getAvailableVariables();

	}

}
